﻿package game.objects {
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import game.events.GameEvent;
	import game.value.GameValues;
	import game.objects.num.*;
	
	public class Pudding extends MovieClip {

		private const starX:int = 100;
		private const starY:int = 530;
		
		private var game:main;
		public var removeTag:Boolean = false;//是否被碰撞到
		private var movieTag:int;
		//private var numMnage:Num;
		private var temp,temp2:OneK;
		 
		public function Pudding(mygame:main) {
			super();
			movieTag = 1;
			game = mygame;
			this.x = this.starX;
			this.y = this.starY;
			
			this.addEventListener(Event.ENTER_FRAME,this.Remove);
			game.stage.addChild(this);
			return;
		}
		
		public function reduceNum(num:Number):void {
			if (movieTag < 6) 
			{
				movieTag += num;
				this.gotoAndStop(movieTag);
				game.gameValue.subPoint(GameValues.Jelly, num);
				//numMnage= new Num(this, GameValues.Jelly, num);
				if (num == 1)
				{
					temp= new OneK(160, 475);
					this.stage.addChild(temp);
				}
				else if (num == 2)
				{
					temp = new OneK(160, 475);
					this.stage.addChild(temp);
					temp2 = new OneK(100, 465);
					this.stage.addChild(temp2);
				}
			}
			else
			{
				trace("movieTage: " + movieTag);
				game.gameValue.gameOver = true;
				game.stage.dispatchEvent(new Event(GameEvent.GAME_OVER, false, false));
				
			}
			return;
		}
		
		//影格變換
		public function Remove (e:Event):void
		{
			if (!game.gameValue.showPudding)
			{
				parent.removeChild(this);
				this.removeEventListener(Event.ENTER_FRAME, this.Remove);
			}
		}
		
	}
	
}
